﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Weight.Model
{
   public  class ExeResult
    {
        /// <summary>
        /// 是否成功
        /// </summary>
        public  bool isSuccess;
        /// <summary>
        /// 展示的消息
        /// </summary>
        public string msg;

        /// <summary>
        /// 是否成功
        /// </summary>
        public bool IsSuccess { get => isSuccess; set => isSuccess = value; }

        /// <summary>
        /// 消息
        /// </summary>
        public string Msg { get => msg; set => msg = value; }

        /// <summary>
        /// 默认状态
        /// </summary>
        /// <returns></returns>
        public static ExeResult  Defalut()
        {
            return new ExeResult { IsSuccess= false, msg="执行失败!" };
        }

        /// <summary>
        /// 执行成功
        /// </summary>
        /// <param name="msg"></param>
        /// <returns></returns>
        public static ExeResult Success(string msg="")
        {
            return new ExeResult { IsSuccess = true, Msg  = msg };
        }

        /// <summary>
        /// 执行失败
        /// </summary>
        /// <param name="msg"></param>
        /// <returns></returns>
        public static ExeResult Faild(string msg="")
        {
            return new ExeResult { IsSuccess = false, Msg = msg };
        }

    }

    /// <summary>
    /// 执行结果支持泛型实体
    /// </summary>
    /// <typeparam name="T"></typeparam>
    public class  ExeResult<T> :ExeResult
    {
        /// <summary>
        /// 实体类
        /// </summary>
       public  T Entity;
        /// <summary>
        /// 默认状态
        /// </summary>
        /// <returns></returns>
        public static ExeResult<T> Defalut(T entity)
        {
            return new ExeResult<T> { IsSuccess = false, msg = "执行失败!", Entity = entity };
        }

        /// <summary>
        /// 执行成功
        /// </summary>
        /// <param name="msg"></param>
        /// <returns></returns>
        public static ExeResult<T> Success(T entity,string msg = "")
        {
            return new ExeResult<T> { IsSuccess = true, Msg = msg, Entity= entity };
        }

        /// <summary>
        /// 执行失败
        /// </summary>
        /// <param name="msg"></param>
        /// <returns></returns>
        public static ExeResult<T> Faild(T entity,string msg = "")
        {
            return new ExeResult<T> { IsSuccess = false, Msg = msg,Entity = entity };
        }
    }

}
